package com._520it.crm.web.controller;

import com._520it.crm.domain.Classroom;
import com._520it.crm.page.AjaxResult;
import com._520it.crm.page.PageResult;
import com._520it.crm.query.ClassroomQueryObject;
import com._520it.crm.service.IClassroomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/classroom")
public class ClassroomController {
	@Autowired
	private IClassroomService classroomService;
	//@RequiresPermissions("classroom:index")
	//@PermissionName("班级列表")
	@RequestMapping("")
	public String index(){
		return "classroom";
	}
	//@RequiresPermissions("classroom:list")
	//@PermissionName("班级数据")
	@RequestMapping("/list")
	@ResponseBody
	public PageResult list(ClassroomQueryObject qo){
		PageResult result = classroomService.queryPage(qo);
		return result;
	}
	//@RequiresPermissions("classroom:save")
	//@PermissionName("班级新增")
	@RequestMapping("/save")
	@ResponseBody
	public AjaxResult save(Classroom classroom){
		AjaxResult result = null;
		try{
			classroomService.insert(classroom);
			result = new AjaxResult(true,"保存成功");
		}catch(Exception e){
			e.printStackTrace();
			result = new AjaxResult("保存失败,请联系管理员!");
		}
		return result;
	}
	//@RequiresPermissions("classroom:update")
	//@PermissionName("班级更新")
	@RequestMapping("/update")
	@ResponseBody
	public AjaxResult update(Classroom classroom){
		AjaxResult result = null;
		try{
			classroomService.updateByPrimaryKey(classroom);
			result = new AjaxResult(true,"更新成功");
		}catch(Exception e){
			e.printStackTrace();
			result = new AjaxResult("更新失败,请联系管理员!");
		}
		return result;
	}
}
